package com.example.myapplication

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class RecyclerViewDemo : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_recycler_view_demo)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 初始化RecyclerView控件
        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)

        // 设置水平布局管理器参数：
        // context - 当前上下文
        // orientation - 布局方向为水平(HORIZONTAL)
        // reverseLayout - false表示不反向排列
        recyclerView.layoutManager = LinearLayoutManager(
            this,
            LinearLayoutManager.HORIZONTAL,
            false
        )


        // 创建20条模拟数据，格式为"黑马程序员 X"，其中X从1开始递增
        val items = List(20) { i -> "黑马程序员 ${i + 1}" }

        // 设置自定义适配器MyAdapter，传入模拟数据列表
        recyclerView.adapter = MyAdapter(items)
    }
}